#!/usr/bin/python
# -*- coding: utf-8 -*-

from app.lib import BaseHandler
from utils.common import auth 
from utils.common import set_navbar 
from utils.common import render 
from web.session import Session
from model.product import ProductManager
from model.order import OrderManager
from igor import logging

class Account(BaseHandler):

    @auth
    def get(self, req, resp):  
        omanager = OrderManager()
        sess = Session(req)
        uid = sess['user'].uid
        orders_buy = omanager.query_orders_buy(uid)
        orders_sell = omanager.query_orders_sell(uid)
        patterns = set_navbar(req)
        patterns.update({'orders_buy': orders_buy, 'orders_sell':orders_sell})
        body = render('account.html', patterns) 
        return resp.respond(body)


class Bought(BaseHandler):

    @auth
    def get(self, req, resp):
        sess = Session(req)
        uid = sess['user'].uid
        omanager = OrderManager()
        orders_buy = omanager.query_orders_buy(uid)
        patterns = set_navbar(req)
        patterns.update({'sell_display': 'none', 'buy_display': 'block',
            'orders_buy': orders_buy})
        body = render('account.html', patterns)
        return resp.respond(body)


class Sale(BaseHandler):

    @auth
    def get(self, req, resp):
        patterns = set_navbar(req)
        sess = Session(req)
        uid = sess['user'].uid
        omanager = OrderManager()
        orders_sell = omanager.query_orders_sell(uid)
        patterns.update({'sell_display': 'block', 'buy_display': 'none', 
            'orders_sell':orders_sell})
        body = render('account.html', patterns)
        return resp.respond(body)
